//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<OutlineConsole.h>
///	@path	~/src/appear/xwin/
///	@date	2007/12/24
///	@desc	A tree view that outlines nearly all accessible nodes in engine.

#pragma once

#include "xeres.h"

#include <deque>

#include "lib/math/rect.h"
#include "lib/utilities/dict.h"
#include "lib/utilities/observer.h"

#include "object/CVar.h"

#include "database/IData.h"

#include "graphics/IFont.h"
#include "graphics/IGeometry.h"
#include "graphics/canvas/CCanvas.h"
#include "graphics/canvas/CCanvasText.h"
#include "graphics/canvas/CCanvasTextBoard.h"
#include "graphics/common/common_vertex_decl.h"
#include "graphics/common/TQuadList.h"

#include "appear/app/key_map.h"
#include "appear/app/console.h"
#include "appear/ctrl/ctrl_edit.h"

namespace xeres {

	/*!
		\class	OutlineConsole
		\brief	A tree view that outlines nearly all accessible nodes in engine.
	*/
	class OutlineConsole : public Console
	{
	public:

		/// \ctor
		OutlineConsole( void );

		/// \dtor
		virtual ~OutlineConsole( void );

	public:

	//@ interface

		/*!
			\brief		Initialize outline console.
		*/
		bool Initialize( Engine& engine , RefWeak<IData> root );

		/*!
			\brief		Finalize console.
		*/
		virtual void Finalize( void );

		/*!
			\brief		Tick update call.
		*/
		virtual void Tick( Engine& engine );

		/*!
			\brief		Render console.
		*/
		virtual void Render( RenderContext& rc );

		/*!
			\brief		Process key input message.
		*/
		virtual HandleInput OnKeyInput( const KeyInput& input );

		/*!
			\brief		Process mouse input message.
		*/
		virtual HandleInput OnMouseInput( const MouseInput& input );

		/*!
			\brief		Callback when active or deactive.
		*/
		virtual void OnActive( bool is_active );

	private:

		// prepare console resources
		void PrepareConsoleResource( RenderContext& rc );

		// update update focus
		void UpdateFocusItem( RenderContext& rc );

		// try to switch to node
		bool SwitchToNode( const WString& path , size_t index );

	//@ data

		// status
		bool					m_actived;
		bool					m_reset;
		bool					m_spare0[2];

		// focus node/item
//		WString					m_focusNode;
//		WString					m_focusItem;
		WString					m_currentPath;
		Ref<IData>				m_currentDir;

		WString					m_focusItem;
		int						m_focusIndex;
		int						m_lastFocusIndex;

		std::deque<DataInfo>		m_info;
		std::deque<TextBoardLine>	m_nodes;

		// console rectangle
		Rect<int>				m_rect;

		// root data entry
		Ref<IData>				m_rootEntry;

		TQuadList<vd::ScreenColor,2>	m_quads;
		Ref<IVertexLayout>				m_vertexLayout;

		// outline canvas screen
		Ref<CCanvas>			m_canvas;
		Ref<CCanvasTextBoard>	m_board;

		// tree font
		Ref<IFont>				m_treeFont;

	};

} // namespace xeres
